<?php
$image_exploded = explode("/", user_input('image'));
$image = array_pop($image_exploded);
foreach($image_exploded as $value){
$dir .= $value . "/";
}
$path = $config['photodir']. $dir;
$dir_handle = @opendir($path) or die("You do not have permission to view - $path");
$pictures = array(' ');
while ($file = readdir($dir_handle)) 
{
	if($file{0} != "."){
	$fileparts = explode('.',$file);
	if($file!="." && $file!=".." && !in_array($file,$config['hide']) && in_array(strtolower(end($fileparts)), $config['ext'])){
			$fullpath = $path . $file;
			$spath = $subpath . $file;
		if(is_dir($path . $file) == FALSE) {
		array_push($pictures, $file);
		}
	}
}
}
sort($pictures);
unset($pictures[0]);
foreach ($pictures as $file){
			if($file == $image){
				$before = $last;
			}
			if($last==$image){
				$after = $file;
			}
		$last = $file;
}	

if (!$config['mod_rewrite']){
	if($before)
		$before = "index.php?act=display&image={$dir}{$before}";
	if($after)
		$after = "index.php?act=display&image={$dir}{$after}";
}else{
	if($before)
		$before = $config['basedir'] ."display/{$dir}{$before}/";
	if($after)
		$after = $config['basedir'] ."display/{$dir}{$after}/>";
}
if($dir){
$album = $dir;
}else{
$album = $config['name'];
}
$smarty->assign('album', $album);
$smarty->assign('imageurl', $config['photodir'] . user_input('image'));
$smarty->assign('imagename', $image);
$smarty->assign('before', $before);
$smarty->assign('after', $after);
$smarty->display("view.tpl");
?>
